package com.hnx.admin.aurora.core;

import com.hnx.admin.aurora.core.api.SqlBuilder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/*
创建人： 倔强的头发
创建时间：2025/7/4
功能描述:

*/
public class SafeDeleteSqlBuilder implements SqlBuilder {
    private final StringBuilder sql = new StringBuilder();
    private final List<Object> params = new ArrayList<>();
    public SafeDeleteSqlBuilder delete(String table){
        sql.append(DELETE).append(table);
        return this;
    }
    public SafeDeleteSqlBuilder where(String condition,Object value){
        sql.append(WHERE).append(condition);
        params.add(value);
        return this;
    }
    public SafeDeleteSqlBuilder whereIn(String condition, Collection<?> value){
        sql.append(WHERE).append(condition).append(" in (");
        String ins = value.stream().map(n-> QUESTION).collect(Collectors.joining(COMMA));
        sql.append(ins).append(RIGHT);
        params.addAll(value);
        return this;
    }
    public SqlWithParams build(){
        return new SqlWithParams(getSql(),params.toArray());
    }
    @Override
    public String getSql() {
        return sql.toString();
    }
}
